/*	
* Copyright 2005-2009 Jesse Andrews
* Copyright 2011 Stepan Riha
*
* This file may be used under the terms of of the
* GNU General Public License Version 3 or later (the "GPL"),
* http://www.gnu.org/licenses/gpl.html
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*/


var stores = [{
	name: 'abebooks',
	title: 'Abebooks',
	link: 'http://www.abebooks.com/servlet/SearchResults?isbn=#{ISBN}',
	// <span class="price">US$ 3.97</span>
	match: /\<span class="price"\>[^\<\d\.]*([\d\.]+?)\<\/span\>/
}, {
	name: 'alibris',
	title: 'Alibris',
	link: 'http://www.alibris.com/booksearch?qsort=p&qisbn=#{ISBN_UPCASE}',
	query: 'http://partnersearch.alibris.com/cgi-bin/search?site=23615740&qisbn=#{ISBN_UPCASE}',
	// <price>11.31</price>
	match: /\<price\>(.*?)\<\/price\>/
}, {
	name: 'amazon',
	title: 'Amazon',
	affiliate_link: "http://www.amazon.com/exec/obidos/ASIN/#{ISBN_UPCASE}/bookburrito-20",
	link: 'http://www.amazon.com/exec/obidos/ASIN/#{ISBN_UPCASE}',
	// <b class="priceLarge">$18.98</b>
	match: /\<b class=\"priceLarge\"\>(.+?)\<\/b\>/
}, {
	name: 'amazon_marketplace',
	title: 'Amazon Marketplace',
	affiliate_link: "http://www.amazon.com/exec/obidos/redirect?tag=bookburrito-20&path=tg/stores/offering/list/-/#{ISBN_UPCASE}/all/",
	link: "http://www.amazon.com/gp/offer-listing/#{ISBN_UPCASE}/",
	// <span class="price">$4.32</span>
	match: /\<span class=\"price\"\>(.+?)\<\/span\>/
}, {
	name: 'barnesnoble_member',
	title: 'Barnes & Noble Member',
	link: 'http://search.barnesandnoble.com/booksearch/isbninquiry.asp?isbn=#{ISBN}',
	query: 'http://search.barnesandnoble.com/booksearch/isbninquiry.asp?isbn=#{ISBN}',
	match: /onlinePriceValue2.*(\$\d+\.\d+)/
}, {
	name: 'betterworldbooksnew',
	title: 'Better World Books - New',
	query: "http://www.betterworldbooks.com/service.aspx?ItemId=#{ISBN_UPCASE}",
	link: 'http://www.betterworldbooks.com/detail.aspx?ItemId=#{ISBN_UPCASE}',
	process: function (req, isbn) {
		var results = req.responseText.match(/\<LowestNewPrice\>(.*?)\<\/LowestNewPrice\>/);
		return (results && results.length > 1 && results[1] != "$0.00") ? results[1] : "no"
	}
}, {
	name: 'betterworldbooksused',
	title: 'Better World Books - Used',
	query: "http://www.betterworldbooks.com/service.aspx?ItemId=#{ISBN_UPCASE}",
	link: 'http://www.betterworldbooks.com/detail.aspx?ItemId=#{ISBN_UPCASE}',
	process: function (req, isbn) {
		var results = req.responseText.match(/\<LowestUsedPrice\>(.*?)\<\/LowestUsedPrice\>/);
		return (results && results.length > 1 && results[1] != "$0.00") ? results[1] : "no"
	}
}, {
	name: 'bookmooch',
	title: 'Book Mooch',
	link: 'http://bookmooch.com/detail/#{ISBN}',
	query: 'http://bookmooch.com/api/moochable?asins=#{ISBN}',
	process: function (req, isbn) {
		if (req.responseText.toLowerCase().match(isbn.toLowerCase())) {
			return 'yes';
		} else {
			return 'no';
		}
	}
}, {
	name: 'booksamillion',
	title: 'Books A Million',
	link: "http://www.booksamillion.com/ncom/books?isbn=#{ISBN}",
	match: /Club Price\:.*(\$\d+\.\d+)/
}, {
	name: 'buy',
	title: 'Buy',
	link: "http://www.buy.com/retail/usersearchresults.asp?qu=#{ISBN}",
	match: /\"searchPrice\".*(\$\d+\.\d+)/
}, {
	name: 'goodreads',
	title: 'GoodReads',
	link: 'http://www.goodreads.com/search?q=#{ISBN}&group_id=&search_type=books',
	query: 'http://www.goodreads.com/search?q=#{ISBN}&group_id=&search_type=books',
	process: function (req, isbn) {
		var results = req.responseText.match(/class=\"average\".*\>([\d\.]+)\</);
		return (results && results.length > 0) ? "Avg. rating: " + results[1] : "no"
	}
}, {
	name: 'half',
	title: 'Half.com',
	link: 'http://search.half.ebay.com/ws/web/HalfSearch?m=books&isbn=#{ISBN}&submit=Search',
	match: /Best[^P]*Price[^\$]*(\$\d+\.\d+)</
}, {
	name: 'librarything',
	title: 'Library Thing',
	link: 'http://www.librarything.com/isbn/#{ISBN}',
	process: function (req, isbn) {
		if (req.responseText.match('No works found')) {
			return 'no';
		}
		return 'yes';
	}
}, {
	name: 'paperbackswap',
	title: 'PaperBackSwap',
	link: 'http://www.paperbackswap.com/book/details/#{ISBN}',
	query: 'http://www.paperbackswap.com/api/v1/index.php?RequestType=ISBNList&ISBN=#{ISBN}',
	process: function (req, isbn) {
		var results = req.responseText.match(/(available) for Swap\s*<\/title>/);
		return (results && results.length > 0) ? "yes" : "no"
	}
}, {
	name: 'powells',
	title: 'Powells',
	link: "http://www.powells.com/biblio?isbn=#{ISBN}",
	query: 'http://www.powells.com/search/linksearch?isbn=#{ISBN}',
	match: /Class: USED(?:.|\n)+?Price: ([\d\.]+)/
}, {
	name: 'shelfari',
	title: 'Shelfari',
	link: 'http://www.shelfari.com/booksearch.aspx?Adv=True&SearchAmazon=False&Title=&Author=&Isbn=#{ISBN}',
	process: function (req, isbn) {
		if (!req.responseText.match('Your search did not return any results')) {
			return 'yes';
		}
		return 'no';
	}
}];